<?php
/*
Overmundo, cultura de todo o Brasil
Desenvolvido pela Tecnopop para o Núcleo de Idéias Movimento
Copyright (C) 2006  Núcleo de Idéias Movimento

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/





// CONFIG GERAL //
if (defined('ABSPATH')) {
	require_once( ABSPATH . 'ov_config.php');
} 
else {
	require_once('../ov_config.php'); // tem que ser relativo!
}

// CONFIG PAGINA //
// dados necessários para o checa_login
$nivelPagina = "desconhecido";
$secaoAtual = "revista";

// includes necessários
require_once(ABSPATH . LIB . '/checa_login.php');
require_once(ABSPATH . INCLUDES . '/_header.php'); // só funcionalidades do header, apresentacao no cabecalho.html
require_once(ABSPATH . INCLUDES . '/barralateral.php');

// libs 
require_once('../lib/class.site.php');
require_once('../lib/class.overmundo.php');
require_once('../lib/class.conecta.php');
require_once("../lib/class.usuario.php");
//include('../lib/class.municipio.inc');

// INIT //
require_once(ABSPATH . SHARED . '/smarty_init.php');
require_once(ABSPATH . SHARED . '/db_init.php');

//vars Smarty cabeçalho
$smarty->assign('saudacaoUsuario',$saudacaoUsuario); // em todas as seções com Login
$smarty->assign('opcoesLogin',$opcoesLogin); // em todas as seções com Login




$minhaConexao = new Conecta();
$meuSite = new Overmundo();
$meuSite->linkid = $minhaConexao->linkid;

$idOK = 0;
if(isset($_POST["etapaRegistro"])) {
	$etapaRegistro = $_POST["etapaRegistro"];
	switch ($_POST["etapaRegistro"]) {
		case 1:
		session_start();
		$c = $_SESSION["usuarioRecupera"];
		$usuarioPagina= new Usuario($meuSite->linkid, $c);
		$senha = $meuSite->limpaCampo($_POST["txtSenhaRecupera"]);
		if ($senha == $meuSite->limpaCampo($_POST["txtSenhaConfirma"])) {
			$usuarioPagina->SetaSenha($senha);
			$usuarioPagina->SetaStatus("ativo");
			$usuarioPagina->update();
			$usuarioLogado=new Usuario($meuSite->linkid, $c);
			$_SESSION["usuarioValido"] = $c;
			if ($_SESSION["iaPara"]) {
				header('location: ' . $_SESSION["iaPara"]);
				exit();
			} 
			//header('location: /');

			$msg =  "funcionou";
		}
		break;
	}
} 
else {

	// testar se veio por um link OK
	if ($c = $meuSite->OvermundoRecuperaSenhaUsuario($meuSite->limpaCampo($_GET["c"]), $meuSite->limpaCampo($_GET["s"]))) {
		session_start();
		$_SESSION["usuarioRecupera"] = $_GET["c"];
		$idOK = 1;
	} 
}

$smarty->assign('idOK', $idOK);
$smarty->assign('msg', $msg);
$smarty->display('templates/recupera_senha.html');

